<template>
  <div class="askbox">
    <div class="askbox-container">
      <Askheader></Askheader>
      <Contentheader></Contentheader>
    </div>
    <div class="btn" @click="xunwen">询问</div>
    <div>我承诺已在实体医疗机构就诊过，所提供的信息真实</div>
  </div>
</template>
 
<script setup>
import Askheader from "./component/askHeader/index.vue";
import Contentheader from "./component/askContent/index.vue";
import soket from "../../../soket/index";
import { useRoute, useRouter } from "vue-router";
import { getCurrentInstance } from "vue";
import store from "@/store/index.ts";
let myStore2 = store();
let { proxy } = getCurrentInstance();
let Route = useRoute();
let router = useRouter();
//得到医生id
let did = Route.query.id;


let xunwen = async () => {
  //当前用户id  当前医生id  用户的评论和照片上传到服务器就是数据库操作
  let res = await proxy.$axios("/getuserid");
  let uid = res.data;
  if (myStore2.doid !== did) {
    myStore2.doid = did;
    proxy.$axios({ url: "/chat", params: { doctorID: did } }); //发送请求，创建一个服务器，端口为医生id
  }


  router.push({ path: "/userchat", query: { id: did } });
  if (uid == 0) {
    alert("未登录请先登录");
    return;
  }
  //   用户的评论和照片上传到服务器就是数据库操作
  let promble = myStore2.msg;
  let photos = myStore2.photos0;
  // console.log(promble,photos,uid,did);

  //把数据传到服务器创建表
  let data = new FormData();
  data.append("uid", uid);
  data.append("did", did);
  data.append("promble", promble);

  for (let i = 0; i < photos.length; i++) {
    data.append("photos" + [i], photos[i]);
  }

  let res1 = await proxy.$axios.post("/productud", data);
  if (res1.data.code == 200) {
    // alert(res1.data.info);
    let ws = soket(fn1, 1000); //将100id传到ws中，成为端口号
    const send = () => {
      //客户端发送信息
      ws.send(
        JSON.stringify({
          nickName: myStore2.username,
        })
      );
    };
    setTimeout(send, 2000);
    function fn1(e) {
      return;
    }
  }
};
</script>

<style scoped lang="scss">
.askbox {
  width: 100%;
  background-color: #f4f4f4;

  .askbox-container {
    caret-color: transparent;
    width: 900px;
    padding: 20px 15px;
    // height: 1000px;
    margin: 0 auto;
    background-color: white;
  }
  .btn {
    width: 800px;
    height: 50px;
    background-color: #00c792;
    line-height: 50px;
    text-align: center;
    color: white;
    margin: 20px auto 0;
    border-radius: 25px;
    cursor: pointer;

    & + div {
      font-size: 12px;
      width: 800px;
      height: 50px;
      line-height: 50px;
      text-align: center;
      margin: 10px auto 20px;
    }
  }
}
</style>